#include "Application.h"
#include "Graphics.h"
#include "Input.h"
#include "Time.h"

#include "Font.h"

#include "Map.h"

#include "Physics.h"

using namespace GenBen;

class MyApplication : public Application
{
public:
	MyApplication()
		: Application("GenBenTest", 480, 272, 1, false, false) 
	{
	};

	virtual void init() 
	{
		getTime()->setFpsLimit(60);
		consolas = new Font(getGraphics(), "consolas.bft");	
		map1 = new Map(getGraphics(), "test1.bmap");
		camera = map1->getCamera();
	};
	
	virtual void close()
	{
		delete map1;
		delete consolas;
	};

	virtual void update() 
	{		
		if(getInput()->isKeyPressed(KEY_UP))
			camera.y -= 4.0f;
		if(getInput()->isKeyPressed(KEY_DOWN))
			camera.y += 4.0f;
		if(getInput()->isKeyPressed(KEY_LEFT))
			camera.x -= 4.0f;
		if(getInput()->isKeyPressed(KEY_RIGHT))
			camera.x += 4.0f;

		map1->moveCamera(camera, getTime()->getTimeScale());
	};

	virtual void render()
	{		
		Time* time = getTime();
		Graphics* graphics = getGraphics();
		graphics->clear(Color(0.0f, 0.0f, 0.0f));	
		
		consolas->draw(time->timeToString(time->getTimeMs()), 127, VectorI(10, 10), Color(1.0f, 1.0f, 1.0f));
				
		char fps_string[16];
		sprintf(fps_string, "%u", time->getFps());
		consolas->draw(fps_string, 127, VectorI(10, 30), Color(1.0f, 1.0f, 1.0f));

		map1->draw();

		graphics->present();
	}
private:
	Font* consolas;
	Map* map1;
	VectorF camera;
};

IMPLEMENT_APP(MyApplication);

